package cn.sx.dao;

/*
 *@program:sx_emall_ssm
 *@author: sx
 *@desc: 管理员接口
 *@Time: 2020/9/20  23:15
 */

import cn.sx.entity.Admins;
import cn.sx.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminDao {

    @Select("SELECT * FROM admins ORDER BY id ")
    List<Admins> findAll();

    /*根据用户名和密码查询（登录）*/
    @Select("select * from admins where username=#{username} and `password`=#{password}")
    public Admins selectByAdminnameAndPassword(@Param("username") String username,
                                            @Param("password") String password);
    /*根据用户米查询管理员*/
    @Select("SELECT * FROM admins WHERE username=#{username}")
    Admins selectAdminByUsername(String username);

    @Insert("INSERT INTO admins(`username`,`password`)VALUE(#{username},#{password}) ")
    /*加密密码*/
    @SelectKey(keyProperty = "id",statement = "SELECT LAST_INSERT_ID()",before = false,resultType = Integer.class)
    boolean addAdmin(Admins admins);
    /*删除管理员*/
    @Delete("delete from admins where id=#{id}")
    int deleteAdmins(int id);
    /*修改后台用户信息*/
    @Update("UPDATE users SET `name`=#{name},phone=#{phone},address=#{address} WHERE id=#{id}")
    public boolean updateUser(User user);

    /*修改后台管理员密码*/
    @Update("UPDATE admins SET `password` = #{password} WHERE id =#{id}")
    boolean updatePassword(@Param("id") int id, @Param("password") String password);

    @Select("select * from admins where id = #{id}")
    Admins select(int id);

    @Select("Select count(*) from admins")
    long selectCount();
}
